/*
 *******************
 ******************************* C HEADER FILE *******************************
 ** 						  *******************						       **
 ** 																		   **
 ** project : ClockSync 											           **
 ** filename :Timer															   **
 ** version : 1 															   **
 ** date : -	2012.04.10.													   **
 ** 																		   **
 *****************************************************************************
 ** 																		   **
 ** Copyright (c) 2012,  						  				               **
 ** All rights reserved.													   **
 ** 																		   **
 *****************************************************************************
 VERSION HISTORY:
 ----------------
 Version : 1
 Date : -
 Revised by : -
 Description : Original version.
 */
#ifndef _TIMER_H_INCLUDED
#define _TIMER_H_INCLUDED

/****************************************************************************/
/** 																	   **/
/** 							MODULES USED 							   **/
/** 																	   **/
/****************************************************************************/

/****************************************************************************/
/** 																	   **/
/** 							DEFINITIONS AND MACROS 					   **/
/** 																	   **/
/****************************************************************************/
/* interrupts priorities are the highest */
#define ISR_PRIOR 0

/* The clocks precision in ppm */
#define CLK_PRECISION 30
/****************************************************************************/
/** 																	   **/
/** 							TYPEDEFS AND STRUCTURES 				   **/
/** 																	   **/
/****************************************************************************/

/****************************************************************************/
/** 																	   **/
/** 							EXPORTED VARIABLES						   **/
/** 																	   **/
/****************************************************************************/
#ifndef _TIMER_C_SRC
cyg_interrupt timer1_int;
cyg_handle_t timer1_int_handle;
#endif

/****************************************************************************/
/** 																	   **/
/** 							EXPORTED FUNCTIONS 						   **/
/** 																	   **/
/****************************************************************************/
/* initialize the Timer1 */
void Timer1_init(void);

/* Update the request timers match register */
void Update_request_timer(cyg_uint32 time_to_add);

/* Update the answer timers match register */
void Update_answer_timer(cyg_uint32 time_to_add);

/* Sets the request timers match register */
void Set_request_timer(cyg_uint32 time_to_set);

/* Sets the answer timers match register */
void Set_answer_timer(cyg_uint32 time_to_set);

/* Sets flag for request and answer threads */
void Timer1_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data);

/* Handle interrupt flag and prepare for dsr. */
cyg_uint32 Timer1_isr(cyg_vector_t vector, cyg_addrword_t data);

/* Get the current time, it is the timer counter actual value */
cyg_uint32 Get_time(void);

/* Set the current time, it is the timer counter actual value */
void Set_time(cyg_uint32 new_time);

#endif
/****************************************************************************/
/** 																	   **/
/** 							EOF 							   		   **/
/** 																	   **/
/****************************************************************************/
